package net.fdukedom.epicurus.client.connection;

import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;

import net.fdukedom.epicurus.client.stub.EpicurusWSInterfacePort;
/**
 * 
 * @author Alexander Kirakozov
 */
public class OpenPortFactory extends ServicePortFactory {

    @Override
    EpicurusWSInterfacePort createPort(String serverURL) {
        try {
            String serviceURL = serverURL + serviceName + wsdlPostfix;
            QName serviceQName = new QName(serviceURL, serviceName);
            URL wsdlLocation = new URL(serviceURL);
            ServiceFactory factory = ServiceFactory.newInstance();
            Service service = factory.createService(wsdlLocation, serviceQName);

            QName portQName = new QName(portURL, portName);
            EpicurusWSInterfacePort port = (EpicurusWSInterfacePort) service
                    .getPort(portQName, EpicurusWSInterfacePort.class);

            return port;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
